﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace SalesSys.Comm.DAL
{
    /// <summary>
    /// 实体基本接口
    /// </summary>
    public interface IDbEntity
    {
        /// <summary>
        /// 得到主键值
        /// </summary>
        /// <returns></returns>
        object[] GetKeyValues();
        /// <summary>
        /// 设置主键值
        /// </summary>
        /// <param name="keyValues"></param>
        void SetKeyValues(object[] keyValues);

    }

    /// <summary>
    /// 逻辑删除实体标识接口
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    public interface ILogicalDelEntity:IDbEntity
    {
        /// <summary>
        /// 逻辑删除标识
        /// </summary>
        bool IsDelete { get; set; }
    }

    public interface ICreateTimeEntity : IDbEntity
    {
        DateTime CreateTime { get; set; }
    }

    /// <summary>
    /// 可版本控制实体标识接口
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    public interface ITimestampEntity  : IDbEntity
    {
        /// <summary>
        /// 并发版本控制,Timestamp
        /// </summary>
       [Timestamp]
        byte[] RowVersion { get; set; }
    }
    public interface IDbEntity<TKey> : IDbEntity
    {
        TKey Id { get; set; }
    }
   

    public interface ITreeEntity : IDbEntity
    {
        ITreeEntity Parent { get; set; }

        IEnumerable <ITreeEntity> Children { get; set; }

        object ParentId { get; set; }
    }

    /// <summary>
    /// 树型数据库实体接口
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    /// <typeparam name="TTReeEntity"></typeparam>
    public interface ITreeEntity<TKey, TTReeEntity> : IDbEntity<TKey>, ITreeEntity where TTReeEntity : ITreeEntity where TKey:struct 
    {
        /// <summary>
        /// 父级ID，关联外键
        /// </summary>
        new TKey? ParentId { get; set; }

        /// <summary>
        /// 父级对象
        /// </summary>
        new TTReeEntity Parent { get; set; }

        /// <summary>
        /// 子对象集合
        /// </summary>
        new ICollection<TTReeEntity> Children { get; set; }
    }

  
}
